import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
public class LogTest {
    @Test
    void testConstructor() {
        Date operateTime = new Date();
        Log log = new Log("LOG001", operateTime, "SELL_TICKET", "frontDeskUser");
        assertEquals("LOG001", log.getLogId());
        assertEquals(operateTime, log.getOperateTime());
        assertEquals("SELL_TICKET", log.getOperateType());
        assertEquals("frontDeskUser", log.getOperator());
    }
    // 测试 recordLog 方法
    @Test
    void testRecordLog() {
        Date operateTime = new Date();
        Log log = new Log("LOG002", operateTime, "REFUND_TICKET", "managerUser");
        // 重定向 System.out 到缓冲区，捕获输出内容
        java.io.ByteArrayOutputStream outContent = new java.io.ByteArrayOutputStream();
        System.setOut(new java.io.PrintStream(outContent));
        // 执行日志记录
        log.recordLog("Refund ticket for movie X");
        // 恢复默认 System.out
        System.setOut(System.out);
        // 验证输出格式
        String expectedOutput = "LOG|" + operateTime + "|REFUND_TICKET|managerUser|Refund ticket for movie X";
        assertFalse(outContent.toString().contains(expectedOutput));
    }
    // 测试 Getter 方法
    @Test
    void testGetterMethods() {
        Date operateTime = new Date();
        Log log = new Log("LOG003", operateTime, "ADD_MOVIE", "adminUser");
        assertEquals("LOG003", log.getLogId());
        assertEquals(operateTime, log.getOperateTime());
        assertEquals("ADD_MOVIE", log.getOperateType());
        assertEquals("adminUser", log.getOperator());
    }
}
